#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAXN=40005;
typedef long long LL;
struct Rectangle{
	LL x1,y1,x2,y2;
};
Rectangle T[MAXN];
LL sum[MAXN];
bool cmp(Rectangle a, Rectangle b) {
	if (a.y2!=b.y2) return a.y2<b.y2;
	else {
		if (a.x2!=b.x2) return a.x2<b.x2;
		else {
			return a.x1>b.x1;
		}
	}
}
int n;
void Cover(LL x1, LL y1, LL x2, LL y2, int k, int now) {
	while (k<n && (x1>=T[k].x2 || x2<=T[k].x1 || y1>=T[k].y2 || y2<=T[k].y1)) ++k;
	if (k>=n) {
		sum[now]+=(x2-x1)*(y2-y1);
		return;
	}
	if (x1<T[k].x1) {
		Cover(x1,y1,T[k].x1,y2,k+1,now);
		x1=T[k].x1;
	}
	if (x2>T[k].x2) {
		Cover(T[k].x2,y1,x2,y2,k+1,now);
		x2=T[k].x2;
	}
	if (y1<T[k].y1) {
		Cover(x1,y1,x2,T[k].y1,k+1,now);
		y2=T[k].y1;
	}
}
int main() {
	LL a,b,c,d;
	freopen("in.txt", "r", stdin);
	while (~scanf("%d", &n)) {
		for (int i=0; i<n; ++i) {
			scanf("%lld%lld%lld", &a, &c, &d);
			T[i].x1=a; T[i].y1=0; T[i].x2=c; T[i].y2=d;
			sum[i]=0;
		}
		sort(T, T+n, cmp);
//		for (int i=0; i<n; ++i) cout<<T[i].x1<<" "<<T[i].y1<<" "<<T[i].x2<<" "<<T[i].y2<<endl;
		for (int i=n-1; i>=0; --i) Cover(T[i].x1, T[i].y1, T[i].x2, T[i].y2, i+1, i);
		LL ans=0;
		for (int i=0; i<n; ++i) {
//			cout<<sum[i]<<endl;
			ans+=sum[i];
		}
		printf("%lld\n", ans);
	}
	return 0;
}
